<?php 
ob_start();
session_start();
$teamid=$_SESSION['teamID'];
?>
<!DOCTYPE html>
<html>
<head>
<title>Match</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="Content/bootstrap.css" rel="stylesheet" />
<link href="Content/bootstrap-datepicker3.css" rel="stylesheet" />
<link href="Content/site.css" rel="stylesheet" />
<script src="Scripts/jquery-1.9.1.js"></script>
<script src="Scripts/bootstrap.js"></script>
<script src="Scripts/bootstrap-datepicker.js"></script>
</head>
<body>
<?php include_once("php/input_result_classes.php");?>
<?php include_once("php/input_result_submit.php");?>
<div class="container blue_border">
<?php 
include_once("php/banner.php");
?>
<?php 
include_once("php/nav_bar.php");
?>
<h1>Input Result</h1>
<?php //$scheduleID=14;
include_once("php/input_result_variables.php");
 ?>
<form action="php/update_players_umpire.php" role="form" method="post" class="form" name="updatePlayers">
    <input type="hidden" name="scaduleId" id="scaduleId" value="<?php echo $roundSchedule->round_scheduleID; ?>" />
      <table class="table table-striped table-bordered align-center ">
        <thead>
          <tr>
            <th>ABC</th>
            <th><?php echo $team1->team_name;?></th>
            <th></th>
            <th>XYZ</th>
            <th><?php echo $team2->team_name;?></th> 
          </tr>
        </thead>
        <tbody>
          <tr>
          	<?php  $playersT1=$repPlayer->maps($repMatch->getplayerT1byRoundScheduleID($roundSchedule->round_scheduleID));?>
          	<td>
            	A <input type="radio" name="player1T1Letter" value="A" id="A1" <?php if ($playersT1[0]->playerID==$matches[0]->player1ID) echo "checked";  ?>> 
                B <input type="radio" name="player1T1Letter" value="B" id="B1" <?php if ($playersT1[0]->playerID==$matches[1]->player1ID) echo "checked";  ?>>
                C <input type="radio" name="player1T1Letter" value="C" id="C1" <?php if ($playersT1[0]->playerID==$matches[2]->player1ID) echo "checked";  ?>>
            </td>
            <td class="align-left"> <input type="hidden" name="player1T1" id="player1T1" value="<?php echo $playersT1[0]->playerID; ?>" /> <?php echo $playersT1[0]->fname." ".$playersT1[0]->sname; ?></td>
            <td rowspan="3" class="vs-inner">VS</td>
            <td>
            <?php $playersT2=$repPlayer->maps($repMatch->getplayerT2byRoundScheduleID($roundSchedule->round_scheduleID)); ?>
            
            	X <input type="radio" name="player1T2Letter" value="X" id="X1" <?php if ($playersT2[0]->playerID==$matches[0]->player2ID) echo "checked";  ?>>
                Y <input type="radio" name="player1T2Letter" value="Y" id="Y1" <?php if ($playersT2[0]->playerID==$matches[1]->player2ID) echo "checked";  ?>>
                Z <input type="radio" name="player1T2Letter" value="Z" id="Z1" <?php if ($playersT2[0]->playerID==$matches[2]->player2ID) echo "checked";  ?>>
                
            </td>
            <td class="align-left"> <input type="hidden" name="player1T2" id="player1T2" value="<?php echo $playersT2[0]->playerID; ?>" /> <?php echo $playersT2[0]->fname." ".$playersT2[0]->sname; ?> </td>
            
          </tr>
          <tr>
            <td>
            	A <input type="radio" name="player2T1Letter" value="A" id="A2" <?php if ($playersT1[1]->playerID==$matches[0]->player1ID) echo "checked";  ?>>
                B <input type="radio" name="player2T1Letter" value="B" id="B2" <?php if ($playersT1[1]->playerID==$matches[1]->player1ID) echo "checked";  ?>>
                C <input type="radio" name="player2T1Letter" value="C" id="C2" <?php if ($playersT1[1]->playerID==$matches[2]->player1ID) echo "checked";  ?>>
                
            </td>
            <td class="align-left"> <input type="hidden" name="player2T1" id="player2T1" value="<?php echo $playersT1[1]->playerID; ?>" /> <?php echo $playersT1[1]->fname." ".$playersT1[1]->sname; ?></td>
            <td>
           		X <input type="radio" name="player2T2Letter" value="X" id="X2" <?php if ($playersT2[1]->playerID==$matches[0]->player2ID) echo "checked";  ?>>
                Y <input type="radio" name="player2T2Letter" value="Y" id="Y2" <?php if ($playersT2[1]->playerID==$matches[1]->player2ID) echo "checked";  ?>>
                Z <input type="radio" name="player2T2Letter" value="Z" id="Z2" <?php if ($playersT2[1]->playerID==$matches[2]->player2ID) echo "checked";  ?>>
                
            </td>
            <td class="align-left"> <input type="hidden" name="player2T2" id="player2T2" value="<?php echo $playersT2[1]->playerID; ?>" /> <?php echo $playersT2[1]->fname." ".$playersT2[1]->sname; ?> </td>    
            </td>

          </tr>
          <tr>
          	<td>
            	A <input type="radio" name="player3T1Letter" data-col="A" value="A" id="A" <?php if ($playersT1[2]->playerID==$matches[0]->player1ID) echo "checked";  ?>>
                B <input type="radio" name="player3T1Letter" data-col="B" value="B" id="B" <?php if ($playersT1[2]->playerID==$matches[1]->player1ID) echo "checked";  ?>>
                C <input type="radio" name="player3T1Letter" data-col="C" value="C" id="C" <?php if ($playersT1[2]->playerID==$matches[2]->player1ID) echo "checked";  ?>>
                
            </td>
            <td class="align-left"> <input type="hidden" name="player3T1" id="player3T1" value="<?php echo $playersT1[2]->playerID; ?>" /> <?php echo $playersT1[2]->fname." ".$playersT1[2]->sname; ?></td>
            <td>
            	
            	X <input type="radio" name="player3T2Letter" value="X" id="X3" <?php if ($playersT2[2]->playerID==$matches[0]->player2ID) echo "checked";  ?>>
                Y <input type="radio" name="player3T2Letter" value="Y" id="Y3" <?php if ($playersT2[2]->playerID==$matches[1]->player2ID) echo "checked";  ?>>
                Z <input type="radio" name="player3T2Letter" value="Z" id="Z3" <?php if ($playersT2[2]->playerID==$matches[2]->player2ID) echo "checked";  ?>>
            </td>
            <td class="align-left"> <input type="hidden" name="player3T2" id="player3T2" value="<?php echo $playersT2[2]->playerID; ?>" /> <?php echo $playersT2[2]->fname." ".$playersT2[2]->sname; ?> </td>    
            
          </tr>
          <tr>
          <td colspan="5"><button class="btn btn-default btn-lg" type="submit" name="submit" onclick = "return  validatePlayerUpdate(this.updatePlayers)">Populate</button></td>
		  </tr>
        </tbody>
      </table>
      </form>
<?php 
	
	foreach($matches as $m){
?>
<div class="panel-group" id="accordion">
<div class="panel panel-default">
  <div class="panel-heading">
    <div class="row"> <a data-toggle="collapse" data-parent="#accordion" href="#match<?php echo $m->matchID;?>">
      <div class="col-md-4"> <?php echo $m->matchNumber;?> </div>
      <div class="col-md-4 col-xs-6">
        <h4 class="panel-title">
          <?php if ($repPlayer->readPlayer($m->player1ID)!=""){
		   $player=$repPlayer->map($repPlayer->readPlayer($m->player1ID));}
					echo $team1->team_name." ".$player->fname." ".$player->sname;?>
        </h4>
      </div>
      <div class="col-md-4 col-xs-6">
        <h4 class="panel-title">
          <?php if ($repPlayer->readPlayer($m->player2ID)!=""){
		  $player=$repPlayer->map($repPlayer->readPlayer($m->player2ID));}
					echo $team2->team_name." ".$player->fname." ".$player->sname;?>
        </h4>
      </div>
      </a> </div>
  </div>
  <div id="match<?php echo $m->matchID?>" class="panel-collapse collapse">
    <div class="panel-body">
      <div class="container-fluid">
        <form class="form" role="form" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" >
          <div class="row">
            <div class="form-group col-md-4 col-xs-12">
              <input type="hidden"  id="matchID" name="matchID" value="<?php echo $m->matchID;?>" >
              <label>Game 1</label>
            </div>
            <div class="form-group col-md-4 col-xs-6">
              <input type="number" class="form-control" id="player1_score1" name="player1_score1" value="<?php if (($repGame->checkGame($m->matchID,1)!=0)&&($repGame->readGame($m->matchID,1)!="")){
				  	
						$game =$repGame->map($repGame->readGame($m->matchID,1));
						echo $game->player1Score;
					}
					else {
						echo "";
					}?>">
            </div>
            <div class="form-group col-md-4 col-xs-6">
              <input type="number" class="form-control" id="player2_score1" name="player2_score1" value="<?php if (($repGame->checkGame($m->matchID,1)!=0)&&($repGame->readGame($m->matchID,1)!="")){
				  	
						$game =$repGame->map($repGame->readGame($m->matchID,1));
						echo $game->player2Score;
					}
					else {
						echo "";
					}?>">
            </div>
          </div>
          <div class="row">
            <div class="form-group col-md-4 col-xs-12">
              <label>Game 2</label>
            </div>
            <div class="form-group col-md-4 col-xs-6">
              <input type="number" class="form-control" id="player1_score2" name="player1_score2" value="<?php if (($repGame->checkGame($m->matchID,2)!=0)&&($repGame->readGame($m->matchID,2)!="")){
				  
						$game =$repGame->map($repGame->readGame($m->matchID,2));
						echo $game->player1Score;
					}
					else {
						echo "";
					}?>">
            </div>
            <div class="form-group col-md-4 col-xs-6">
              <input type="number" class="form-control" id="player2_score2" name="player2_score2" value="<?php if (($repGame->checkGame($m->matchID,2)!=0)&&($repGame->readGame($m->matchID,2)!="")){
				  
						$game =$repGame->map($repGame->readGame($m->matchID,2));
						echo $game->player2Score;
					}
					else {
						echo "";
					}?>">
            </div>
          </div>
          <div class="row">
            <div class="form-group col-md-4 col-xs-12">
              <label>Game 3</label>
            </div>
            <div class="form-group col-md-4 col-xs-6">
              <input type="number" class="form-control" id="player1_score3" name="player1_score3" value="<?php if (($repGame->checkGame($m->matchID,3)!=0)&&($repGame->readGame($m->matchID,3)!="" )){
				 
						$game =$repGame->map($repGame->readGame($m->matchID,3));
						echo $game->player1Score;
					}
					else {
						echo "";
					}?>">
            </div>
            <div class="form-group col-md-4 col-xs-6">
              <input type="number" class="form-control" id="player2_score3" name="player2_score3" value="<?php if (($repGame->checkGame($m->matchID,3)!=0)&&($repGame->readGame($m->matchID,3)!="" )){
						$game =$repGame->map($repGame->readGame($m->matchID,3));
						echo $game->player2Score;
					}
					else {
						echo "";
					}?>">
            </div>
          </div>
          <div class="row">
            <button class="btn btn-default" type="submit" name="submit">Submit</button>
          </div>
        </form>
      </div>
    </div>
  </div>
</div>
<?php	} ?>
<div class="panel-group" id="accordion">
<div class="panel panel-default">
  <div class="panel-heading">
    <div class="row"> <a data-toggle="collapse" data-parent="#accordion" href="#doubles1">
      <div class="col-md-4"> </div>
      <div class="col-md-4 col-xs-6">
        <h4 class="panel-title"> <?php echo $team1->team_name." Doubles 1";?> </h4>
      </div>
      <div class="col-md-4 col-xs-6">
        <h4 class="panel-title"> <?php echo $team2->team_name." Doubles 1"; ?> </h4>
      </div>
      </a> </div>
  </div>
  <div id="doubles1" class="panel-collapse collapse">
    <div class="panel-body">
      <div class="container-fluid">
        <form class="form" role="form" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" >
          <?php 
	include_once("php/input_result_doubles_variables.php");
	for ($i=0; $i<3; $i++){
		
?>
          <div class="row">
            <div class="form-group col-md-4 col-xs-12">
              <input type="hidden"  id="roundSchedule" name="roundSchedule" value="<?php echo $roundSchedule->round_scheduleID;?>" >
              <label><?php echo "Doubles Game  ";
				echo $i+1;?></label>
            </div>
            <div class="form-group col-md-4 col-xs-6">
              <input type="number" class="form-control" id="team1Points<?php echo $i;?>" name="team1Points<?php echo $i;?>" value="<?php if ($doubles[$i]->team1Points!=0){
						echo $doubles[$i]->team1Points;
					}
					else {
						echo "";
					}?>">
            </div>
            <div class="form-group col-md-4 col-xs-6">
              <input type="number" class="form-control" id="team2Points<?php echo $i;?>" name="team2Points<?php echo $i;?>" value="<?php if ($doubles[$i]->team2Points!=0){
						echo $doubles[$i]->team2Points;
					}
					else {
						echo "";
					}?>">
            </div>
          </div>
          <?php	} ?>
          <div class="row">
            <button class="btn btn-default" type="submit" name="submit">Submit</button>
          </div>
        </form>
      </div>
    </div>
  </div>
</div>
<div class="panel-group" id="accordion">
  <div class="panel panel-default">
    <div class="panel-heading">
      <div class="row"> <a data-toggle="collapse" data-parent="#accordion" href="#doubles2">
        <div class="col-md-4"> </div>
        <div class="col-md-4 col-xs-6">
          <h4 class="panel-title"> <?php echo $team1->team_name." Doubles 2";?> </h4>
        </div>
        <div class="col-md-4 col-xs-6">
          <h4 class="panel-title"> <?php echo $team2->team_name." Doubles 2"; ?> </h4>
        </div>
        </a> </div>
    </div>
    <div id="doubles2" class="panel-collapse collapse">
      <div class="panel-body">
        <div class="container-fluid">
          <form class="form" role="form" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" >
            <?php 
	include_once("php/input_result_doubles_variables.php");
	for ($i=3; $i<6; $i++){
		
?>
            <div class="row">
              <div class="form-group col-md-4 col-xs-12">
                <input type="hidden"  id="roundSchedule" name="roundSchedule" value="<?php echo $roundSchedule->round_scheduleID;?>" >
                <label><?php echo "Doubles Game  ";
				echo $i+1;?></label>
              </div>
              <div class="form-group col-md-4 col-xs-6">
                <input type="number" class="form-control" id="team1Points<?php echo $i;?>" name="team1Points<?php echo $i;?>" value="<?php if ($doubles[$i]->team1Points!=0){
						echo $doubles[$i]->team1Points;
					}
					else {
						echo "";
					}?>">
              </div>
              <div class="form-group col-md-4 col-xs-6">
                <input type="number" class="form-control" id="team2Points<?php echo $i;?>" name="team2Points<?php echo $i;?>" value="<?php if ($doubles[$i]->team2Points!=0){
						echo $doubles[$i]->team2Points;
					}
					else {
						echo "";
					}?>">
              </div>
            </div>
            <?php	} ?>
            <div class="row">
              <button class="btn btn-default" type="submit" name="submit">Submit</button>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</div>
          <?php ob_flush();?>
</body>
</html>
